home *** CD-ROM | disk | FTP | other *** search
- #!perl -w
- # Special MPW glue
- undef;
-
- package MakeImports;
-
- require Exporter;
- @ISA = 'Exporter';
- @EXPORT = qw(MakeImports);
-
- # MakeImports
-
- # Note: The TargetDir sub below uses the readlink builtin, which in MacPerl
- # constructs a pathname based on the information stored in the alias, without
- # actually attempting to resolve it. This is unfortunate -- especially because
- # of, but not as much as, the Finder's neglect to update aliases as it resolves
- # them. Said again: MacPerl's readlink doesn't resolve aliases, and the Finder
- # doesn't update them when it uses them. So, either we use a MacPerl extension,
- # or we make the user fix the aliases (unless we enroll Matthias into enhancing
- # readlink). We make the user do it.
- #
- # If readlink is producing bad pathnames, then select the problematic aliases
- # in the Finder, and run the Recreate Aliases script (AppleScript). You must do
- # this without changing the Finder selection, of course -- you can use the
- # Script Editor, or install OSA Menu and put an alias of the script in the Finder
- # Scripts folder and run it that way (recommended).
-
- use SCF;
-
- use strict;
-
- Main() unless defined caller;
-
- sub Main {
- my $output = MakeImports(@ARGV);
- foreach (@$output) {
- print;
- }
- }
-
- sub Unique {
- my @list;
- my $item;
- while ($item = shift) {
- push @list, $item unless grep {$_ eq $item} @list;
- }
- return @list;
- }
-
- sub ResolveDir {
- my ($pathname) = @_;
- my $original = readlink($pathname);
- if (defined $original) {
- -d $original or die "Stale alias '$pathname'";
- return $original;
- } else {
- -d $pathname or die "Missing directory '$pathname'";
- return $pathname;
- }
- }
-
- sub TargetDir {
- my ($target, $dir) = @_;
- # Assumes MPW environment
- $dir ||= "Menu";
- my ($pathname, $original);
- $pathname = ResolveDir("$ENV{Boot}Development");
- $pathname = ResolveDir("$pathname:$dir");
- $pathname = ResolveDir("$pathname:$target");
- return "$pathname:"
- }
-
- sub MakeImports {
- my $scf = SCF::Read(@_);
- my %dirs;
- my @source;
- my (@includes, @sysincludes);
- my %libraries;
- my @resources;
- foreach my $section (SCF::Sections($scf)) {
- my $srcs = SCF::Lookup($scf, $section, 'Sources');
- if (defined $srcs) {
- foreach my $src (split ' ', $srcs) {
- push @source, $src;
- my ($ext) = $src =~ /\.(\w+?)$/;
- push @{$dirs{$ext}}, TargetDir($section) . "Sources:";
- }
- }
- my $incs = SCF::Lookup($scf, $section, 'Include');
- if (defined $incs) {
- foreach my $inc (split ' ', $incs) {
- my ($ext) = $inc =~ /\.(\w+?)$/;
- my $dir = TargetDir($section) . "Includes:";
- push @{$dirs{$ext}}, $dir;
- push @includes, "$dir";
- }
- }
- my $sysincs = SCF::Lookup($scf, $section, 'SysInclude');
- if (defined $sysincs) {
- foreach my $sysinc (split ' ', $sysincs) {
- my ($ext) = $sysinc =~ /\.(\w+?)$/;
- my $dir = TargetDir($section) . "Includes:";
- push @{$dirs{$ext}}, $dir;
- push @sysincludes, "$dir";
- }
- }
- my $libs = SCF::Lookup($scf, $section, 'Libraries');
- if (defined $libs) {
- foreach my $lib (split ' ', $libs) {
- my $dir = TargetDir($section, "Lab")
- . '(Libraries):$(ARCH):$(COMPILER):$(BUILD):';
- push @{$libraries{''}}, "$dir$lib";
- }
- }
- my $syslibs = SCF::Lookup($scf, $section, 'SysLibraries');
- if (defined $syslibs) {
- my $arch = SCF::Lookup($scf, $section, 'Arch');
- my $compiler = SCF::Lookup($scf, $section, 'Compiler');
- foreach my $syslib (split ' ', $syslibs) {
- my $dir = TargetDir($section, "Menu") . "<Libraries>:";
- push @{$libraries{join('-', '', $arch || (), $compiler || ())}}, "$dir$syslib";
- }
- }
- my $rezs = SCF::Lookup($scf, $section, 'Resources');
- if (defined $rezs) {
- foreach my $rez (split ' ', $rezs) {
- my $dir = TargetDir($section) . "Resources:";
- push @resources, "$dir$rez";
- }
- }
- }
-
- my @output;
- foreach my $ext (sort keys %dirs) {
- length $ext or $ext = "NULL";
- push @output, ".SOURCE.$ext : "
- . join('', '"', join('" "', Unique(@{$dirs{$ext}})), '"', "\n");
- }
- push @output, "\n";
- foreach my $libs (keys %libraries) {
- push @output, "LIBS$libs = ", join(' ', map { qq("$_") } @{$libraries{$libs}}), "\n";
- }
- push @output, 'ALLLIBS = $(LIBS) $(LIBS-$(ARCH)) $(LIBS-$(ARCH)-$(COMPILER))', "\n";
- push @output, "REZS = ", join(' ', map { qq("$_") } @resources), "\n";
-
- push @output, "MORESRCS = ", join(' ', @source), "\n";
- sub I { "-i '$_'" }
- push @output, "CINCLUDES = ",
- join(' ', (map { I } @includes)), "\n";
- push @output, "CSYSINCLUDES = ",
- join(' ', (map { I } @sysincludes)), "\n";
-
- return \@output;
- }
-
- 1;
-